﻿namespace Colorful.Control
{
    using System.ComponentModel;
    using Properties;

    public class ConfigureProxyViewModel : INotifyPropertyChanged
    {
        private string proxyAddress;
        private bool useDefaultProxy;

        public ConfigureProxyViewModel()
        {
            ProxyAddress = Settings.Default.ProxyAddress;
            UseDefaultProxy = Settings.Default.UseDefaultProxy;
        }

        public bool UseDefaultProxy
        {
            get { return useDefaultProxy; }
            set
            {
                useDefaultProxy = value;
                Settings.Default.UseDefaultProxy = value;
                Settings.Default.Save();
                RaisePropertyChanged("UseDefaultProxy");
            }
        }

        public string ProxyAddress
        {
            get { return proxyAddress; }
            set
            {
                proxyAddress = value;
                Settings.Default.ProxyAddress = value;
                Settings.Default.Save();
                RaisePropertyChanged("ProxyAddress");
            }
        }

        #region INotifyPropertyChanged Members
        public event PropertyChangedEventHandler PropertyChanged;

        private void RaisePropertyChanged(string name)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(name));
        }
        #endregion INotifyPropertyChanged Members
    }
}